<!--
 * @Description: 修改某一条数据
 * @Author: 马山
 * @Date: 2020-03-30 15:36:26
 * @LastEditTime: 2020-03-30 12:43:55
 * @LastEditors: 马山
 -->
<template>
    <el-dialog :title="options.title" :close-on-click-modal="false" :visible="isShow" class="modifyDetailDialog" :before-close="closeDialog">

        <el-form :model="options" status-icon :rules="rules" ref="rulesFrom" label-position="left" label-width="80px" size="mini">
            
            <el-form-item :label="options.label" prop="data">
                <el-input v-model="options.data" clearable type="text" 
                    onkeyup="this.value=this.value.replace(/[^\d-]/g,'')" 
                    oninput="if(value.length>20)value=value.slice(0,20)" maxlength="20">
                </el-input>
            </el-form-item>

        </el-form>

        <div slot="footer" class="dialog-footer">
            <button class="el-button el-button--primary" @click="submit">确 定</button>
            <button class="el-button el-button--info" @click="closeDialog">取 消</button>
        </div>
    </el-dialog>

    
</template>

<script>



export default {
    name: "modify-detail-dialog",
    props: {
        // options:{
        //     type:Object,
        //     required:true,
        //     default:{}
        // }
    },
    components: {},
    computed: {},
    data(){
        return {
            isShow:false,
            options:{
                title:"", //标题
                label:"",
                data:""
            },
            
            //新建修改时的校验规则
            rules:{
                data:[  //单位ID
                    { required: true, message: ' ', trigger: 'blur' },
                    // { min: 3, max: 5, message: ' ', trigger: 'blur' }
                ]
            }
        }
    },
    created() {},
    mounted() {},
    watch: {},
    methods: {

        // 组件入口
        open(data){
            this.isShow = true;
            this.options = JSON.parse(JSON.stringify(data));
            this.options.oldOrderSn = this.options.data;
            this.title = this.options.title;
        },
        // 提交
        submit(){
            
            this.checkRules( () =>{ //校验一次
                this.api.updateOrderSn(
                    {
                        newOrderSn:this.options.data,//新输入的订单号
                        oldOrderSn:this.options.oldOrderSn //原来的订单号
                    },{loading:true}
                ).then(res =>{
                    console.log(res);
                    this.$emit("submit",this.options.data);
                    this.closeDialog();
                }).catch(err =>{
                    console.log(err);
                });
            });
            
            
        },
        //检查校验
        checkRules(call){
            this.$refs.rulesFrom.validate((valid) => {
                if (valid) {
                    call && call();
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },

        closeDialog(){
            this.isShow = false;
            this.$refs.rulesFrom.resetFields(); //重置
        },

    }
};
</script>
